package org.mbds.sensorsdatacollector.android.view;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MapOverlay extends Overlay {

    private GeoPoint data;  
    private Bitmap bmp;
    private Activity ctx;

    public MapOverlay(GeoPoint item, Bitmap bt, Activity context) {
        data = item;
        bmp = bt;
        ctx = context;
    }
    
    public void changeLocation(GeoPoint newLocation) {
    	data = newLocation;
    }

    /* (non-Javadoc)
    * @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean, long)
    */
    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,long when) {
        Projection projection = mapView.getProjection();
        if (shadow == false) {
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            Point point = new Point();
            projection.toPixels(data, point);
            canvas.drawPoint((float) point.x, (float) point.y , paint);
            		canvas.drawBitmap(bmp,(float) point.x-bmp.getWidth(), (float) point.y-bmp.getHeight(), null);            }
        return super.draw(canvas, mapView, shadow, when);
    }

    /* (non-Javadoc)
    * @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
    */
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

        super.draw(canvas, mapView, shadow);
    } 
    
//    @Override
//	public boolean onTap(GeoPoint p, MapView map) {
//    	ApplicationMenu.indoor(ctx);
//		return false;
//    }
    
}